Reaching GenAI usage limit Exception (internal)#195
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ntgbaoo
commented
Mar 27, 2026
Comment on lines
+408
to
+420
| @ExceptionHandler(GenAIServiceException.class) | ||
| public ResponseEntity<Map<String, Object>> handleGenAIServiceException(GenAIServiceException ex) { | ||
|
|
||
| String errorMessage = "ERROR: GenAI Service failed: " + ex.getMessage(); | ||
| log.error(errorMessage); | ||
| return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
| .body( | ||
| Map.of( | ||
| "error", | ||
| SystemErrorCode.INTERNAL_ERROR, | ||
| "message", | ||
| "GenAI Service failed. Please try again later.")); | ||
| } |
Member
Author
There was a problem hiding this comment.
I realized I missed handling this exception so I added it here
gloox
previously approved these changes
Mar 27, 2026
EricHodgson
reviewed
Mar 28, 2026
| geminiClient.models.generateContent(this.model, prompt, null); | ||
| return response.text(); | ||
| } catch (Exception e) { | ||
| if (e.getMessage().contains("429")) { |
Collaborator
There was a problem hiding this comment.
think we could do something like this? not sure if that works with this Exception object but im not a huge fan of checking the message like this.
if (e.getStatusCode() == HttpStatus.TOO_MANY_REQUESTS) {
Member
Author
There was a problem hiding this comment.
Good point. Tks. But getStatusCode is not defined in Exception. But your idea is right, there is a better way to do this:
catch (ApiException e) {
if (e.code() == HttpStatus.TOO_MANY_REQUESTS.value() || (e.code() >= 500 && e.code() < 600)) {
// This includes 503 - SERVICE UNAVAILABLE and 500 - INTERNAL ERROR
throw new GenAIOutOfServiceException(e.getMessage());
}
throw new GenAIServiceException(e.getMessage());
}
|
EricHodgson
approved these changes
Mar 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary / Description
Detect when we reach
Geminiusage limit and return 503 instead of 500Related Issues: # (issue number)
Type of Change
Test Evidence
Describe how this PR has been tested.
Questions / Discussion Points
List any areas where you’d like reviewer input or have open questions.